import router from 'umi/router';
import {
  getMainDevToken,
  fresh,
  startConfig,
} from '../services/global';
import { message } from 'antd';

export default {
  namespace: 'global',
  state: {
    departmentList: [],
    hospitalList: [],
    doctorList: [],
    registationList: [],
  },

  effects: {
    *getMainDevToken({ payload, callback }, { call, put }) {
      try {
        const res = yield call(getMainDevToken, payload);
        callback(res.data);
      } catch (e) {
        message.error(e.message);
        callback();
      }
    },
    *fresh({ payload, callback }, { call, put }) {
      try {
        const res = yield call(fresh, payload);
        if (res.code === 200) {
          callback(res.data);
        }
      } catch (e) {
        message.error(e.message);
        callback();
      }
    },

    //启用配置
    *startConfig({ payload, callback }, { call, put }) {
      try {
        yield call(startConfig, payload);
        message.info('启用成功')
      } catch (e) {
        message.error(e.message);
      } finally {
        callback();
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
